home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / lds / graf.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  4KB  |  174 lines

  1. /*************************************************************************
  2.  *                                                                       *
  3.  *  Copyright (c) 1992, 1993 Ronald Joe Record                           *
  4.  *                                                                       *
  5.  *  All rights reserved. No part of this program or publication may be   *
  6.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  7.  *  or translated into any language or computer language, in any form or *
  8.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  9.  *  biological, or otherwise, without the prior written permission of:   *
  10.  *                                                                       *
  11.  *      Ronald Joe Record (408) 458-3718                                 *
  12.  *      212 Owen St., Santa Cruz, California 95062 USA                   *
  13.  *                                                                       *
  14.  *************************************************************************/
  15.  
  16. #include "x.h"
  17. #include "defines.h"
  18. #include "externals.h"
  19. #include "xexterns.h"
  20.  
  21. /* routines in this file */
  22. void grafline(), grafgen(), phasediff(), draw_hist(), draw_spa();
  23.  
  24. /* external routines called in this file */
  25. extern void BufferPoint(), FlushBuffer(), spahist(), hist(), Clear();
  26. extern void BufferInPixmap(), BufferSpace(), FlushHisbuf();
  27.  
  28. extern XPoint *hpoints;
  29.  
  30. void
  31. grafline(line)
  32. double *line;
  33. {
  34.     static int i;
  35.  
  36.     if (hflag)
  37.         hist(line);
  38.     if (sflag)
  39.         spahist(line);
  40.     if (draw && (!parity)) {
  41.         col++;
  42.         if (col == numcolors) col=mincolor;
  43.         if (eflag)
  44.             Clear(canvas);
  45.         if (Pflag) {
  46.             for (i=0;i<wide;i++)
  47.                 BufferPoint(dpy, canvas, pixmap, Data_GC, &Points, col, 
  48.                             i, (int)((1.0 - line[i])*height));
  49.             FlushBuffer(dpy, canvas, pixmap, Data_GC, &Points, col, col+1);
  50.         }
  51.         else {
  52.             for (i=0; i<wide; i++) {
  53.                 hpoints[i].x = i;
  54.                 hpoints[i].y = (int)((1.0-line[i])*height);
  55.             }
  56.             XDrawLines(dpy,canvas,Data_GC[col],hpoints,wide,CoordModeOrigin);
  57.             XDrawLines(dpy,pixmap,Data_GC[col],hpoints,wide,CoordModeOrigin);
  58.         }
  59.     }
  60. }
  61.  
  62. void
  63. grafgen(line)
  64. double *line;
  65. {
  66.     int i;
  67.  
  68.     if (hflag)
  69.         hist(line);
  70.     if (sflag)
  71.         spahist(line);
  72.     if (draw && (!parity)) {
  73.         for (i=0; i<wide; i++) {
  74.             if (mflag) {
  75.                 if (line[i] > 0.5)
  76.                     BufferInPixmap(dpy, pixmap, Data_GC, &Points, 
  77.                                 mincolor + 1, xpoint + i, height - ypoint - 1);
  78.                 else
  79.                     BufferInPixmap(dpy, pixmap, Data_GC, &Points, 
  80.                             (numcolors+mincolor)/2, xpoint+i, height-ypoint-1);
  81.             }
  82.             else
  83.                 BufferInPixmap(dpy, pixmap, Data_GC, &Points, 
  84.                             (int)(line[i]*(numcolors-mincolor-1))+mincolor, 
  85.                             xpoint + i, height - ypoint - 1);
  86.         }
  87.         ypoint++;
  88.         if (ypoint >= height) {
  89.             ypoint = 0;
  90.             xpoint += wide;
  91.             if ((xpoint + wide) > width)
  92.                 xpoint = 0;
  93.         }
  94.         if ((ypoint >= high) && (!quilt))
  95.             ypoint = 0;
  96.     }
  97. }
  98.  
  99. void
  100. phasediff(line)
  101. double *line;
  102. {
  103.     int i;
  104.  
  105.     if (draw && (!parity)) {
  106.         if (boundflag == 1)
  107.             diff[0] = 0.0;
  108.         else if (boundflag == 2)
  109.             diff[0] = fabs(line[0] - drand48());
  110.         else if (boundflag == 3)
  111.             diff[0] = fabs(line[0] - boundary);
  112.         else
  113.             diff[0] = fabs(line[0]-line[wide-1]);
  114.         if (diff[0] > RANGE)
  115.             diff[0] = (diff[0]-RANGE)/ORANGE;
  116.         else
  117.             diff[0] = 0.0;
  118.         for (i=1; i<wide; i++) {
  119.             diff[i] = fabs(line[i]-line[i-1]);
  120.             if (diff[i] > RANGE)
  121.                 diff[i] = (diff[i]-RANGE)/ORANGE;
  122.             else
  123.                 diff[i] = 0.0;
  124.         }
  125.         if (cflag)
  126.             grafline(diff);
  127.         else
  128.             grafgen(diff);
  129.     }
  130. }
  131.  
  132. void
  133. draw_spa()
  134. {
  135.     static int i, j, k, spacol;
  136.     extern int maxhist, minhist;
  137.  
  138.     k = numcolors - mincolor - 1;
  139.     for (j=0;j<height;j++) {
  140.         for (i=0;i<width;i++) {
  141.             if (histarray[i][j]) {
  142.                 spacol = ((histarray[i][j] - minhist) * k / maxhist) + mincolor;
  143.                 BufferSpace(spacol, i,  j);
  144.             }
  145.         }
  146.     }
  147.     FlushHisbuf();
  148. }
  149.  
  150. void
  151. draw_hist()
  152. {
  153.     int i;
  154.     unsigned long numsites;
  155.  
  156.     numsites = high*wide*(numgen - begin - 1)/60;
  157.     if (numsites) {
  158.         Clear(hiswin);
  159.         for (i=0;i<wide;i++) {
  160.             hpoints[i].x = i;
  161.             hpoints[i].y = height - (int)(histogram[i]*height/numsites);
  162.         }
  163.         if (Pflag)
  164.             XDrawPoints(dpy, hiswin, Data_GC[histcol], hpoints, wide,
  165.                     CoordModeOrigin);
  166.         else
  167.             XDrawLines(dpy, hiswin, Data_GC[histcol], hpoints, wide,
  168.                     CoordModeOrigin);
  169.         histcol++;
  170.         if (histcol >= numcolors)
  171.             histcol = mincolor;
  172.     }
  173. }
  174.